import { _decorator, Label, Node } from 'cc';
import { games } from 'yycore';

const { ccclass, property } = _decorator;

@ccclass('yy.MessageBox')
export class YYMessageBox extends games.ui.MessageBox {

    // 消息框标题文本组件
    @property(Label)
    private readonly lbTitle: Label = null;

    // 消息内容文本组件
    @property(Label)
    private readonly lbContent: Label = null;

    // 关闭按钮
    @property(Node)
    private readonly ndClose: Node = null;

    // 底部按钮组
    @property([Node])
    private readonly ndButtons: Node[] = [];

    start() {

    }

    initMessageBox(data: games.ui.MessageBoxData) {
        // 标题
        if (this.lbTitle && data.name)
            this.lbTitle.string = data.name;

        // 文本内容
        if (this.lbContent)
            this.lbContent.string = data.text;

        // 是否使用广告领取替换普通YES
        const useBtnAD: boolean = data.param && !!data.param.useBtnAD;

        switch (data.btnType) {
            case games.ui.MBBtnType.Yes:
                this.ndClose.active = false;
                this.ndButtons[0].active = !useBtnAD;
                this.ndButtons[1].active = useBtnAD;
                this.ndButtons[2].active = false;
                break;
            case games.ui.MBBtnType.YesNo:
                this.ndClose.active = false;
                this.ndButtons[0].active = !useBtnAD;
                this.ndButtons[1].active = useBtnAD;
                this.ndButtons[2].active = true;
                break;
            case games.ui.MBBtnType.YesNoCancel:
                this.ndClose.active = true;
                this.ndButtons[0].active = !useBtnAD;
                this.ndButtons[1].active = useBtnAD;
                this.ndButtons[2].active = true;
                break;
        }
    }

    show() {
    }

    hide() {
        this.onHideEnd();
    }


}

